package com.wgy.day36常见的函数式接口.Consumer接口;

import java.util.function.Consumer;

/**
 * Created by pc on 2020/12/10 21:54
 * Description: LearningJava
 */
/*
练习:字符串数组中存在多条信息,请按照格式:"姓名:XX,性别:X."的格式将信息打印出来

要求:将打印姓名的动作作为第一个Consumer接口的Lambda实例,
     将打印性别的动作作为第二个Consume接口的Lambda实例
     将两个Consumer接口按照顺序"拼接"到一起
 */
public class Demo03ConsumerTest {
    //定义一个方法,参数传递字符串数组和两个Consumer接口
    public static void printInfo(String[] arr, Consumer<String> con1,Consumer<String> con2){
        for (String s : arr) {
            con1.andThen(con2).accept(s);
        }
    }

    public static void main(String[] args) {
        //定义一个字符串类型的数组
        String[] arr={"迪丽热巴,女","古力娜扎,女","马尔扎哈,男","努尔哈赤,男"};

        printInfo(arr,
                (s)->{
                    String[] arr1 = s.split(",");
                    String name=arr1[0];
                    System.out.print("姓名:"+name+",");

                },
                (s)->{
                    String[] arr2 = s.split(",");
                    String sex=arr2[1];
                    System.out.println("性别:"+sex+".");

                });
    }
}
